﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace Model
{
	[Serializable()]
	public class HoaDonBanBO : Csla.BusinessBase<HoaDonBanBO>
	{
		#region Business Properties
		
private int? _HoaDonBanID = null;
public int? HoaDonBanID
{
get { return this._HoaDonBanID; }
set { this._HoaDonBanID = value; PropertyHasChanged("HoaDonBanID"); }
}

private string _MaSo = "0";
public string MaSo
{
get { return this._MaSo; }
set { this._MaSo = value; PropertyHasChanged("MaSo"); }
}

private string _ChungTu = null;
public string ChungTu
{
get { return this._ChungTu; }
set { this._ChungTu = value; PropertyHasChanged("ChungTu"); }
}

private int? _KhachHangID = null;
public int? KhachHangID
{
get { return this._KhachHangID; }
set { this._KhachHangID = value; PropertyHasChanged("KhachHangID"); }
}

private DateTime? _NgayLapHoaDon = null;
public DateTime? NgayLapHoaDon
{
get { return this._NgayLapHoaDon; }
set { this._NgayLapHoaDon = value; PropertyHasChanged("NgayLapHoaDon"); }
}

private string _NoiDung = null;
public string NoiDung
{
get { return this._NoiDung; }
set { this._NoiDung = value; PropertyHasChanged("NoiDung"); }
}

private string _GhiChu = null;
public string GhiChu
{
get { return this._GhiChu; }
set { this._GhiChu = value; PropertyHasChanged("GhiChu"); }
}

private int? _NguoiLapHoaDonID = null;
public int? NguoiLapHoaDonID
{
get { return this._NguoiLapHoaDonID; }
set { this._NguoiLapHoaDonID = value; PropertyHasChanged("NguoiLapHoaDonID"); }
}

private int? _KeToanID = null;
public int? KeToanID
{
get { return this._KeToanID; }
set { this._KeToanID = value; PropertyHasChanged("KeToanID"); }
}

private int? _GiamDocID = null;
public int? GiamDocID
{
get { return this._GiamDocID; }
set { this._GiamDocID = value; PropertyHasChanged("GiamDocID"); }
}

private int? _NguoiGiaoHangID = null;
public int? NguoiGiaoHangID
{
get { return this._NguoiGiaoHangID; }
set { this._NguoiGiaoHangID = value; PropertyHasChanged("NguoiGiaoHangID"); }
}

private string _NguoiNhanHang = null;
public string NguoiNhanHang
{
get { return this._NguoiNhanHang; }
set { this._NguoiNhanHang = value; PropertyHasChanged("NguoiNhanHang"); }
}

private double? _TongSo = null;
public double? TongSo
{
get { return this._TongSo; }
set { this._TongSo = value; PropertyHasChanged("TongSo"); }
}

private double? _ThanhTien = null;
public double? ThanhTien
{
get { return this._ThanhTien; }
set { this._ThanhTien = value; PropertyHasChanged("ThanhTien"); }
}

private double? _TienPhaiThu = null;
public double? TienPhaiThu
{
get { return this._TienPhaiThu; }
set { this._TienPhaiThu = value; PropertyHasChanged("TienPhaiThu"); }
}

private string _BangChu = null;
public string BangChu
{
get { return this._BangChu; }
set { this._BangChu = value; PropertyHasChanged("BangChu"); }
}

private double? _TienKhachTra = null;
public double? TienKhachTra
{
get { return this._TienKhachTra; }
set { this._TienKhachTra = value; PropertyHasChanged("TienKhachTra"); }
}

private double? _TienThua = null;
public double? TienThua
{
get { return this._TienThua; }
set { this._TienThua = value; PropertyHasChanged("TienThua"); }
}

private double? _TienPhatSinh = null;
public double? TienPhatSinh
{
get { return this._TienPhatSinh; }
set { this._TienPhatSinh = value; PropertyHasChanged("TienPhatSinh"); }
}

private string _LyDoPhatSinh = null;
public string LyDoPhatSinh
{
get { return this._LyDoPhatSinh; }
set { this._LyDoPhatSinh = value; PropertyHasChanged("LyDoPhatSinh"); }
}

private double? _MucVAT = null;
public double? MucVAT
{
get { return this._MucVAT; }
set { this._MucVAT = value; PropertyHasChanged("MucVAT"); }
}

private double? _MucGiamGia = null;
public double? MucGiamGia
{
get { return this._MucGiamGia; }
set { this._MucGiamGia = value; PropertyHasChanged("MucGiamGia"); }
}

private double? _MucPhucVu = null;
public double? MucPhucVu
{
get { return this._MucPhucVu; }
set { this._MucPhucVu = value; PropertyHasChanged("MucPhucVu"); }
}

private double? _MucChietKhau = null;
public double? MucChietKhau
{
get { return this._MucChietKhau; }
set { this._MucChietKhau = value; PropertyHasChanged("MucChietKhau"); }
}

private int? _ThanhToan = null;
public int? ThanhToan
{
get { return this._ThanhToan; }
set { this._ThanhToan = value; PropertyHasChanged("ThanhToan"); }
}

private int? _TinhTrangThanhToan = null;
public int? TinhTrangThanhToan
{
get { return this._TinhTrangThanhToan; }
set { this._TinhTrangThanhToan = value; PropertyHasChanged("TinhTrangThanhToan"); }
}

private int? _HinhThucThanhToanID = null;
public int? HinhThucThanhToanID
{
get { return this._HinhThucThanhToanID; }
set { this._HinhThucThanhToanID = value; PropertyHasChanged("HinhThucThanhToanID"); }
}

private int? _TinhTrangXuatKho = null;
public int? TinhTrangXuatKho
{
get { return this._TinhTrangXuatKho; }
set { this._TinhTrangXuatKho = value; PropertyHasChanged("TinhTrangXuatKho"); }
}

private int? _USRC = Session.LoginID;
public int? USRC
{
get { return this._USRC; }
set { this._USRC = value; PropertyHasChanged("USRC"); }
}

private DateTime? _DATC = DateTime.MaxValue;
public DateTime? DATC
{
get { return this._DATC; }
set { this._DATC = value; PropertyHasChanged("DATC"); }
}

private int? _USRM = null;
public int? USRM
{
get { return this._USRM; }
set { this._USRM = value; PropertyHasChanged("USRM"); }
}

private DateTime? _DATM = null;
public DateTime? DATM
{
get { return this._DATM; }
set { this._DATM = value; PropertyHasChanged("DATM"); }
}

private bool? _DELE = false;
public bool? DELE
{
get { return this._DELE; }
set { this._DELE = value; PropertyHasChanged("DELE"); }
}

		private int? _STT0 = 0;
		public int? STT0
		{
			get { return _STT0; }
			set { _STT0 = value; PropertyHasChanged("STT0"); }
		}
		
		protected override object GetIdValue()
		{
			return _HoaDonBanID.Value;
		}
		#endregion Business Properties
		//==========================================================================
		
		#region Factory Methods
		public void SetIsNew()
		{
			MarkNew();
		}

		public void SetIsOld()
		{
			MarkOld();
		}
		
		public void SetIsDirty()
        {
            MarkDirty();
        }

        public object GetValue(string fieldName)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            return propInfo.GetValue(this, null);
        }

        public void SetValue(string fieldName, object value)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            propInfo.SetValue(this, value, null);
            MarkDirty();
        }
		
		private static int newHoaDonBanID =  -1;
private HoaDonBanBO()
{
_HoaDonBanID = newHoaDonBanID--;
}

		public HoaDonBanBO(SqlDataReader dataReader)
		{
			MarkAsChild();
			Fetch(dataReader);
			MarkOld();
		}

		public HoaDonBanBO(SqlDataReader dataReader, bool isRoot)
		{
			if (!isRoot)
                MarkAsChild();
			Fetch(dataReader);
			MarkOld();
		}

		public static HoaDonBanBO NewRootHoaDonBanBO()
		{
			return DataPortal.Create<HoaDonBanBO>(new RootCriteria());
		}

		internal static HoaDonBanBO NewChildHoaDonBanBO()
		{
			return DataPortal.Create<HoaDonBanBO>(new ChildCriteria());
		}

		public static HoaDonBanBO GetRootHoaDonBanBO(int _HoaDonBanID)
		{
			return DataPortal.Fetch<HoaDonBanBO>(new RootCriteria(_HoaDonBanID));
		}

		public static HoaDonBanBO GetRootHoaDonBanBOByWhere(string where)
		{
			return DataPortal.Fetch<HoaDonBanBO>(where);
		}

		internal static HoaDonBanBO GetChildHoaDonBanBO(SqlDataReader dataReader)
		{
			return new HoaDonBanBO(dataReader);
		}

		public static void DeleteHoaDonBanBO(int _HoaDonBanID)
		{
			DataPortal.Delete(new RootCriteria(_HoaDonBanID));
		}

		public static void DeleteHoaDonBanBO(int _HoaDonBanID, bool directDelete)
		{
			DataPortal.Delete(new RootCriteria(_HoaDonBanID, directDelete));
		}
		#endregion Factory Methods
		//==========================================================================
		
		#region Criteria
		[Serializable()]
		public class RootCriteria
		{
			public int HoaDonBanID;
			public bool directDelete = false;
			public RootCriteria(int _HoaDonBanID)
			{
				this.HoaDonBanID = _HoaDonBanID;
				this.directDelete = false;
			}
			
			public RootCriteria(int _HoaDonBanID, bool directDelete)
            {
                this.HoaDonBanID = _HoaDonBanID;
                this.directDelete = directDelete;
            }
            
			public RootCriteria() {}
		}

		[Serializable()]
		public class ChildCriteria
		{
			public int HoaDonBanID;
			public bool directDelete = false;
			public ChildCriteria(int _HoaDonBanID)
			{
				this.HoaDonBanID = _HoaDonBanID;
				this.directDelete = false;
			}
			
			public ChildCriteria(int _HoaDonBanID, bool directDelete)
            {
                this.HoaDonBanID = _HoaDonBanID;
                this.directDelete = directDelete;
            }
            
			public ChildCriteria() {}
		}
		#endregion Criteria
		//==========================================================================

		#region Create
		[RunLocal]
		private void DataPortal_Create(RootCriteria criteria)
		{
		}

		private void DataPortal_Create(ChildCriteria criteria)
		{
			MarkAsChild();
			ValidationRules.CheckRules();
		}

		#endregion Create
		//==========================================================================

		#region Fetch
		[Transactional(TransactionalTypes.TransactionScope)]
		protected void DataPortal_Fetch(RootCriteria criteria)
		{
			this.Execute_Fetch(criteria);
		}

		protected void DataPortal_Fetch(string where)
		{
			this.Execute_Fetch(where);
		}

		protected void Execute_Fetch(RootCriteria criteria)
		{
			this.This_Fetch(criteria);
		}
		
		protected void Execute_Fetch(string where)
		{
			this.This_Fetch(where);
		}

		private void This_Fetch(RootCriteria criteria)
		{
			SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
			SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HoaDonBanBO_GetBO");
			db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, "[HoaDonBanID] = " + criteria.HoaDonBanID);
			using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
					Fetch(dataReader);                    
			}
		}

		private void This_Fetch(string where)
		{
			SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
			SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HoaDonBanBO_GetBO");
			db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, where);
			using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
					Fetch(dataReader);                    
			}
		}

		private void Fetch(SqlDataReader dataReader)
		{
			if (!(dataReader["HoaDonBanID"] is DBNull))
this._HoaDonBanID = (int)dataReader["HoaDonBanID"];
if (!(dataReader["MaSo"] is DBNull))
this._MaSo = (string)dataReader["MaSo"];
if (!(dataReader["ChungTu"] is DBNull))
this._ChungTu = (string)dataReader["ChungTu"];
if (!(dataReader["KhachHangID"] is DBNull))
this._KhachHangID = (int)dataReader["KhachHangID"];
if (!(dataReader["NgayLapHoaDon"] is DBNull))
this._NgayLapHoaDon = (DateTime)dataReader["NgayLapHoaDon"];
if (!(dataReader["NoiDung"] is DBNull))
this._NoiDung = (string)dataReader["NoiDung"];
if (!(dataReader["GhiChu"] is DBNull))
this._GhiChu = (string)dataReader["GhiChu"];
if (!(dataReader["NguoiLapHoaDonID"] is DBNull))
this._NguoiLapHoaDonID = (int)dataReader["NguoiLapHoaDonID"];
if (!(dataReader["KeToanID"] is DBNull))
this._KeToanID = (int)dataReader["KeToanID"];
if (!(dataReader["GiamDocID"] is DBNull))
this._GiamDocID = (int)dataReader["GiamDocID"];
if (!(dataReader["NguoiGiaoHangID"] is DBNull))
this._NguoiGiaoHangID = (int)dataReader["NguoiGiaoHangID"];
if (!(dataReader["NguoiNhanHang"] is DBNull))
this._NguoiNhanHang = (string)dataReader["NguoiNhanHang"];
if (!(dataReader["TongSo"] is DBNull))
this._TongSo = (double)dataReader["TongSo"];
if (!(dataReader["ThanhTien"] is DBNull))
this._ThanhTien = (double)dataReader["ThanhTien"];
if (!(dataReader["TienPhaiThu"] is DBNull))
this._TienPhaiThu = (double)dataReader["TienPhaiThu"];
if (!(dataReader["BangChu"] is DBNull))
this._BangChu = (string)dataReader["BangChu"];
if (!(dataReader["TienKhachTra"] is DBNull))
this._TienKhachTra = (double)dataReader["TienKhachTra"];
if (!(dataReader["TienThua"] is DBNull))
this._TienThua = (double)dataReader["TienThua"];
if (!(dataReader["TienPhatSinh"] is DBNull))
this._TienPhatSinh = (double)dataReader["TienPhatSinh"];
if (!(dataReader["LyDoPhatSinh"] is DBNull))
this._LyDoPhatSinh = (string)dataReader["LyDoPhatSinh"];
if (!(dataReader["MucVAT"] is DBNull))
this._MucVAT = (double)dataReader["MucVAT"];
if (!(dataReader["MucGiamGia"] is DBNull))
this._MucGiamGia = (double)dataReader["MucGiamGia"];
if (!(dataReader["MucPhucVu"] is DBNull))
this._MucPhucVu = (double)dataReader["MucPhucVu"];
if (!(dataReader["MucChietKhau"] is DBNull))
this._MucChietKhau = (double)dataReader["MucChietKhau"];
if (!(dataReader["ThanhToan"] is DBNull))
this._ThanhToan = (int)dataReader["ThanhToan"];
if (!(dataReader["TinhTrangThanhToan"] is DBNull))
this._TinhTrangThanhToan = (int)dataReader["TinhTrangThanhToan"];
if (!(dataReader["HinhThucThanhToanID"] is DBNull))
this._HinhThucThanhToanID = (int)dataReader["HinhThucThanhToanID"];
if (!(dataReader["TinhTrangXuatKho"] is DBNull))
this._TinhTrangXuatKho = (int)dataReader["TinhTrangXuatKho"];
if (!(dataReader["USRC"] is DBNull))
this._USRC = (int)dataReader["USRC"];
if (!(dataReader["DATC"] is DBNull))
this._DATC = (DateTime)dataReader["DATC"];
if (!(dataReader["USRM"] is DBNull))
this._USRM = (int)dataReader["USRM"];
if (!(dataReader["DATM"] is DBNull))
this._DATM = (DateTime)dataReader["DATM"];
if (!(dataReader["DELE"] is DBNull))
this._DELE = (bool)dataReader["DELE"];

		}
		#endregion Fetch
		//==========================================================================

		#region Insert
		[Transactional(TransactionalTypes.TransactionScope)]
		protected override void DataPortal_Insert()
		{
			this.Execute_Insert();
		}

		protected void Execute_Insert()
		{
			this.This_Insert();
		}

		private void This_Insert()
		{
			this._USRC = Session.LoginID;
this._DATC = DateTime.MaxValue;
this._USRM = null;
this._DATM = null;
this._DELE = false;

			SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
			SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HoaDonBanBO_InsertBO");
			db.AddInParameter(cmd, "@MaSo", SqlDbType.NVarChar, this._MaSo);
db.AddInParameter(cmd, "@ChungTu", SqlDbType.NVarChar, this._ChungTu);
db.AddInParameter(cmd, "@KhachHangID", SqlDbType.Int, this._KhachHangID);
db.AddInParameter(cmd, "@NgayLapHoaDon", SqlDbType.DateTime, this._NgayLapHoaDon);
db.AddInParameter(cmd, "@NoiDung", SqlDbType.NVarChar, this._NoiDung);
db.AddInParameter(cmd, "@GhiChu", SqlDbType.NVarChar, this._GhiChu);
db.AddInParameter(cmd, "@NguoiLapHoaDonID", SqlDbType.Int, this._NguoiLapHoaDonID);
db.AddInParameter(cmd, "@KeToanID", SqlDbType.Int, this._KeToanID);
db.AddInParameter(cmd, "@GiamDocID", SqlDbType.Int, this._GiamDocID);
db.AddInParameter(cmd, "@NguoiGiaoHangID", SqlDbType.Int, this._NguoiGiaoHangID);
db.AddInParameter(cmd, "@NguoiNhanHang", SqlDbType.NVarChar, this._NguoiNhanHang);
db.AddInParameter(cmd, "@TongSo", SqlDbType.Float, this._TongSo);
db.AddInParameter(cmd, "@ThanhTien", SqlDbType.Float, this._ThanhTien);
db.AddInParameter(cmd, "@TienPhaiThu", SqlDbType.Float, this._TienPhaiThu);
db.AddInParameter(cmd, "@BangChu", SqlDbType.NVarChar, this._BangChu);
db.AddInParameter(cmd, "@TienKhachTra", SqlDbType.Float, this._TienKhachTra);
db.AddInParameter(cmd, "@TienThua", SqlDbType.Float, this._TienThua);
db.AddInParameter(cmd, "@TienPhatSinh", SqlDbType.Float, this._TienPhatSinh);
db.AddInParameter(cmd, "@LyDoPhatSinh", SqlDbType.NVarChar, this._LyDoPhatSinh);
db.AddInParameter(cmd, "@MucVAT", SqlDbType.Float, this._MucVAT);
db.AddInParameter(cmd, "@MucGiamGia", SqlDbType.Float, this._MucGiamGia);
db.AddInParameter(cmd, "@MucPhucVu", SqlDbType.Float, this._MucPhucVu);
db.AddInParameter(cmd, "@MucChietKhau", SqlDbType.Float, this._MucChietKhau);
db.AddInParameter(cmd, "@ThanhToan", SqlDbType.Int, this._ThanhToan);
db.AddInParameter(cmd, "@TinhTrangThanhToan", SqlDbType.Int, this._TinhTrangThanhToan);
db.AddInParameter(cmd, "@HinhThucThanhToanID", SqlDbType.Int, this._HinhThucThanhToanID);
db.AddInParameter(cmd, "@TinhTrangXuatKho", SqlDbType.Int, this._TinhTrangXuatKho);
db.AddInParameter(cmd, "@USRC", SqlDbType.Int, this._USRC);
db.AddOutParameter(cmd, "@NewHoaDonBanID", SqlDbType.Int, 10);
db.AddOutParameter(cmd, "@NewDATC", SqlDbType.DateTime, 4);
			db.ExecuteNonQuery(cmd);
			this._HoaDonBanID = (int)cmd.Parameters["@NewHoaDonBanID"].Value;
this._DATC = (DateTime)cmd.Parameters["@NewDATC"].Value;
		}
		#endregion Insert
		//==========================================================================

		#region Update
		[Transactional(TransactionalTypes.TransactionScope)]
		protected override void DataPortal_Update()
		{
			this.Execute_Update();
		}

		protected void Execute_Update()
		{
			this.This_Update();
		}

		private void This_Update()
		{
			this._USRM = Session.LoginID;
this._DATM = DateTime.Now;

			SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
			SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HoaDonBanBO_UpdateBO");
			db.AddInParameter(cmd, "@HoaDonBanID", SqlDbType.Int, this._HoaDonBanID);
db.AddInParameter(cmd, "@MaSo", SqlDbType.NVarChar, this._MaSo);
db.AddInParameter(cmd, "@ChungTu", SqlDbType.NVarChar, this._ChungTu);
db.AddInParameter(cmd, "@KhachHangID", SqlDbType.Int, this._KhachHangID);
db.AddInParameter(cmd, "@NgayLapHoaDon", SqlDbType.DateTime, this._NgayLapHoaDon);
db.AddInParameter(cmd, "@NoiDung", SqlDbType.NVarChar, this._NoiDung);
db.AddInParameter(cmd, "@GhiChu", SqlDbType.NVarChar, this._GhiChu);
db.AddInParameter(cmd, "@NguoiLapHoaDonID", SqlDbType.Int, this._NguoiLapHoaDonID);
db.AddInParameter(cmd, "@KeToanID", SqlDbType.Int, this._KeToanID);
db.AddInParameter(cmd, "@GiamDocID", SqlDbType.Int, this._GiamDocID);
db.AddInParameter(cmd, "@NguoiGiaoHangID", SqlDbType.Int, this._NguoiGiaoHangID);
db.AddInParameter(cmd, "@NguoiNhanHang", SqlDbType.NVarChar, this._NguoiNhanHang);
db.AddInParameter(cmd, "@TongSo", SqlDbType.Float, this._TongSo);
db.AddInParameter(cmd, "@ThanhTien", SqlDbType.Float, this._ThanhTien);
db.AddInParameter(cmd, "@TienPhaiThu", SqlDbType.Float, this._TienPhaiThu);
db.AddInParameter(cmd, "@BangChu", SqlDbType.NVarChar, this._BangChu);
db.AddInParameter(cmd, "@TienKhachTra", SqlDbType.Float, this._TienKhachTra);
db.AddInParameter(cmd, "@TienThua", SqlDbType.Float, this._TienThua);
db.AddInParameter(cmd, "@TienPhatSinh", SqlDbType.Float, this._TienPhatSinh);
db.AddInParameter(cmd, "@LyDoPhatSinh", SqlDbType.NVarChar, this._LyDoPhatSinh);
db.AddInParameter(cmd, "@MucVAT", SqlDbType.Float, this._MucVAT);
db.AddInParameter(cmd, "@MucGiamGia", SqlDbType.Float, this._MucGiamGia);
db.AddInParameter(cmd, "@MucPhucVu", SqlDbType.Float, this._MucPhucVu);
db.AddInParameter(cmd, "@MucChietKhau", SqlDbType.Float, this._MucChietKhau);
db.AddInParameter(cmd, "@ThanhToan", SqlDbType.Int, this._ThanhToan);
db.AddInParameter(cmd, "@TinhTrangThanhToan", SqlDbType.Int, this._TinhTrangThanhToan);
db.AddInParameter(cmd, "@HinhThucThanhToanID", SqlDbType.Int, this._HinhThucThanhToanID);
db.AddInParameter(cmd, "@TinhTrangXuatKho", SqlDbType.Int, this._TinhTrangXuatKho);
db.AddInParameter(cmd, "@USRM", SqlDbType.Int, this._USRM);
db.AddInParameter(cmd, "@DELE", SqlDbType.Bit, this._DELE);

db.AddOutParameter(cmd, "@NewDATM", SqlDbType.DateTime, 4);
			db.ExecuteNonQuery(cmd);
			
this._DATM = (DateTime)cmd.Parameters["@NewDATM"].Value;
		}
		#endregion Update
		//==========================================================================

		#region Delete
		[Transactional(TransactionalTypes.TransactionScope)]
		protected void DataPortal_DeleteSelf()
		{
			DataPortal_Delete(new RootCriteria(_HoaDonBanID.Value));
		}

		private void DataPortal_Delete(RootCriteria criteria)
		{
			this.Execute_Delete(criteria);
		}

		protected void Execute_Delete(RootCriteria criteria)
		{
			SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
			SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HoaDonBanBO_DeleteBO");
			db.AddInParameter(cmd, "@DirectDelete", SqlDbType.Bit, criteria.directDelete);
			db.AddInParameter(cmd, "@HoaDonBanID", SqlDbType.Int, criteria.HoaDonBanID);
			db.ExecuteNonQuery(cmd);
		}
		#endregion Delete
		//==========================================================================

		#region Internal method
		internal void Insert()
		{
			if (!this.IsDirty) return;
			DataPortal_Insert();
			MarkOld();
		}

		internal void Update()
		{
			if (!this.IsDirty) return;
			DataPortal_Update();
			MarkOld();
		}

		internal void DeleteSelf()
		{
			if (!this.IsDirty) return;
			if (this.IsNew) return;
			DataPortal_Delete(new RootCriteria(_HoaDonBanID.Value));
			MarkNew();
		}
		#endregion Internal method
		//==========================================================================
	}
}
